package cn.xing.managementSystem.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author cuixing
 * @package cn.xing.managementSystem.domain
 * @class BaseEntity
 * @email xing.cui@magicwindow.cn
 * @date 2018/4/21 上午11:30
 * @description
 */

@Data
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
    private static final long serialVersionUID = -1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
    @JSONField(name = "id")
    @JsonProperty("id")
    private Long id;

    @Column(name = "date_created", nullable = false, updatable = false)
//    @JSONField(name = "date_created")
//    @JsonProperty("date_created")
    @JsonIgnore
    @JSONField(serialize = false)
    @Temporal(TemporalType.TIMESTAMP)
    @CreationTimestamp
    private Date dateCreated;

    @Column(name = "last_updated", nullable = false)
//    @JSONField(name = "last_updated")
//    @JsonProperty("last_updated")
    @JsonIgnore
    @JSONField(serialize = false)
    @Temporal(TemporalType.TIMESTAMP)
    @UpdateTimestamp
    private Date lastUpdated;

    @Column(name = "deleted", nullable = false)
//    @JSONField(name = "deleted")
//    @JsonProperty("deleted")
    @JsonIgnore
    @JSONField(serialize = false)
    private boolean deleted = false;

    @Column(name = "version")
    @JSONField(name = "version")
    @JsonProperty("version")
    @Version
    private Long version;

}